package com.student.controller;

import com.student.model.User;
import com.student.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;
    //用户登录查询
    @GetMapping("get")
    public User login(@RequestParam("username") String name, @RequestParam("pwd") String password){
        return userService.login(name,password);
    }
    //查询所有用户
    @GetMapping("all")
    public List<User>  getAllUsers(){
        return userService.getAllUsers();
    }
    //通过Id删除用户
    @DeleteMapping("delete")
    public int deleteUserById(Integer id){
        int count = userService.deleteUserById(id);
        return count;
    }
    //修改用户信息
    @PutMapping("put")
    public int putUserInfo(@RequestBody User user){
        int count = userService.putUserInfo(user);
        return count;
    }
    //批量添加用户信息
    @PostMapping("batch")
    public int insertBatchUser(@RequestBody List<User> users){
        return userService.insertBatchUser(users);
    }
    //批量删除用户信息
    @DeleteMapping("batchDelete")
    public int deleteBatchUser(@RequestBody List<Integer> id){
        return userService.deleteBathUser(id);
    }
}
